{include file="public/header" /}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.css"}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.js"}
<style >
    #des, #des input {
        width: 40px;
        text-align: center;
    }

    #id {
        width: 78px;
    }

    .bs-checkbox {
        width: 36px;
        height: 40px
    }

    .fixed-table-toolbar .columns, .fixed-table-toolbar .search {
        margin-left: 0px;
        margin-top: 0px
    }

    #title span {
        float: right;
    }

    .asdlkjasd {
        background: #1ab394;
        color: #fff
    }

    td {
        word-wrap: break-word;
        word-break: break-all;
        max-width: 700px;
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        {include file="public/tophead"}
        {include file="public/top" /}
        <div class="ibox-content">
            {include file="public/topsection"}
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="example">
                        <form class="form-horizontal" method="post">
                        <table data-toggle="table">
                            <thead>
                            <tr>
                                <th class="bs-checkbox"><input type="checkbox" id="delidAll"></th>
                                <th data-align="center">ID</th>
                                <th data-align="center">发送方</th>
                                <!--<th data-align="center">    </th>-->
                                <th data-align="center">接收方</th>
                                <th>内容</th>
                                <th data-align="center">金币</th>
                                <th data-align="center">积分</th>
                                <th data-align="center">收益状态</th>
                                <!--<th data-align="center">类型</th>-->
                                <!--<th data-align="center">是否为客服消息</th>-->
                                <th data-align="center">时间</th>
                                <th data-align="center">管理</th>
                            </tr>
                            </thead>
                            <tbody id="form">
                            {volist name="data" id="v"}
                            <tr id="id{$v.id}" class="class">
                                <td id="delid" ><input name="delAll[]" type="checkbox" value="{$v.id}"></td>
                                <?php $v = getcontent($v['id']); ?>
                                <td>{$v.id}</td>
                                <td><a onClick="add('{:url('member/add',['id'=>$v['userid'],'url'=>-1])}')" style="color:#40BCF7">{:getname($v.userid)}</a><br > ({$v.userid})</td>
                                <!--<td>>>>></td>-->
                                <td><a onClick="add('{:url('member/add',['id'=>$v['touserid'],'url'=>-1])}')" style="color:#40BCF7">{:getname($v.touserid)}</a> <br > ({$v.touserid})</td>
                                <td>
                                    {switch name="$v.type"}
                                        {case value="-1"}<span style="color:#490">{eq name="v.status" value="3"}[消息已撤回]{else}[提示]{/eq}</span>
                                        {php}
                                            if(strpos($v['content'],'/disk/uploads')!==false){
                                                if(strpos($v['content'],'.mp3')!==false){
                                        {/php}
                                            <audio src="{:strpos($v.content, 'http')===false?'__ROOT__':''}{$v.content}" controls="controls">Your browser does not support the audio element.</audio>
                                        {php}
                                                } else {
                                        {/php}
                                            <a href="{present name='$v.content'}{:strpos($v.content, 'http')===false?'__ROOT__':''}{$v.content}{/present}" target="_blank">
                                                <img src="{present name='$v.content'}{:strpos($v.content, 'http')===false?'__ROOT__':''}{$v.content}{else /}__IMG__add_img.png{/present}" id="imageimg" style="max-width: 100%;max-height: 600px">
                                            </a>
                                        {php}
                                                }
                                            } else {
                                        {/php}
                                        {:biaoqing($v.content)}
                                        {php}
                                            }
                                        {/php}
                                        {/case}
                                        {case value="1"}
                                            <a href="{present name='$v.content'}{:strpos($v.content, 'http')===false?'__ROOT__':''}{$v.content}{/present}" target="_blank">
                                                <img src="{present name='$v.content'}{:strpos($v.content, 'http')===false?'__ROOT__':''}{$v.content}{else /}__IMG__add_img.png{/present}" id="imageimg" style="max-width: 100%;max-height: 600px">
                                            </a>
                                        {/case}
                                        {case value="2"}<audio src="{:strpos($v.content, 'http')===false?'__ROOT__':''}{$v.content}" controls="controls">Your browser does not support the audio element.</audio>{/case}
                                        {case value="5"}[红包] {:biaoqing($v.content)}{/case}
                                        {case value="9"}
                                        [语音通话] 
                                        {php}
                                            $jsondata = json_decode($v['data'], true);
                                            echo isset($jsondata['end']) && isset($jsondata['start']) ? $jsondata['end'] - $jsondata['start'] : 0;
                                        {/php}秒 
                                        {php}echo isset($jsondata['hpr']) ? ' 异常挂断原因'.$jsondata['hpr'] : '';
                                        {/php}
                                        <div style="color:skyblue; cursor: pointer;" onclick='showLianmaiDetail({php}echo $v['data'];{/php})'>
                                            通话详情
                                        </div>
                                        {/case}
                                        {case value="10"}
                                        [视频通话] 
                                        {php}
                                            $jsondata = json_decode($v['data'], true);
                                            echo isset($jsondata['end']) && isset($jsondata['start']) ? $jsondata['end'] - $jsondata['start'] : 0;
                                        {/php}秒 
                                        {php}echo isset($jsondata['hpr']) ? ' 异常挂断原因'.$jsondata['hpr'] : '';
                                        {/php}
                                        <div style="color:skyblue; cursor: pointer;" onclick='showLianmaiDetail({php}echo $v['data'];{/php})'>
                                            通话详情
                                        </div>
                                        {/case}
                                        {default /}{:biaoqing($v.content)}
                                    {/switch}
                                </td>
                                <td>{$v.money}</td>
                                <td>{$v.score}</td>
                                <td>
                                    {if condition='$v.score > 0'}
                                        {eq name='$v.finish' value='0'}
                                            <span style="color:red">待领取</span>
                                        {else /}
                                            <span style="color:#1ab394">结束</span>
                                        {/eq}
                                    {/if}
                                </td>
                                <td>{$v.addtime}</td>
                                    <td>
                                        <a onclick="chat('{$v.userid},{$v.touserid}')" style="color:#40BCF7">查看对话</a>
                                    </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        </form>
                    </div>
                </div>
            </div>
            <hr>
            <div class="row row-lg">
                <div class="col-sm-6">
                    <div  class="btn btn-outline btn-default" onclick="alla('del')">
                        批量删除
                    </div>
                </div>
                <div class="col-sm-12 pages">{$page}</div>
            </div>
        </div>
    </div>
</div>
<div id="LianmaiDetail" style="text-align:center;display:none;margin: 0px 30px;padding:10px 100px">
</div>
<script>
    $(document).ready(function(){
        $('#delidAll').click(function(){
            $('input[type=checkbox]').each(function(){
                var self=$(this);
                if(!self.prop('checked')){
                    self.prop('checked',true);
                }else{
                    self.prop('checked',false);
                }
            });
        })
    });
    function alla(){
        var all = $(".form-horizontal").serialize();

        ajaxFun("post",'{:url("delGroupAll")}',all,'json',function(ret){
            if(ret){
                swal_msg('操作成功')
                window.location.reload();
            }
        })
    }

    function chat(uids)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("usertalk/records")}?search=userid&name='+uids
            });
        });
    }
/* 将时间戳格式化为yyyy-MM-dd hh:mm:ss格式，其它格式可自行更改 */
function formatTimeMills(timeMills){
    var date = new Date(timeMills);
    var timeStr = '';
    timeStr += date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours();
    timeStr += ':';
    timeStr += date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes();
    timeStr += ':';
    timeStr += date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds();
    return timeStr;
}
    function showLianmaiDetail(orderData) {
        // console.log(orderData)
        let html = ''
        if (orderData.end && orderData.end > orderData.start) {
            html += `<div class="form-control">计费开始时间：<span style="font-weight:bold;">${formatTimeMills(orderData.start*1000)}</span></div>`
            html += `<div class="form-control">计费结束时间：<span style="font-weight:bold;">${formatTimeMills(orderData.end*1000)}</span></div>`
            html += `<div class="form-control">通话时长：<span style="font-weight:bold;">${orderData.end - orderData.start}秒</span></div>`
        } else {
            html += `<div class="form-control">通话时长：<span style="font-weight:bold;">0秒</span></div>`
        }
        html += `<div class="form-control">订单ID：<span style="font-weight:bold;">${orderData.orderid}</span></div>`
        html += `<div class="form-control">支付用户：<span style="font-weight:bold;">${orderData.payer}</span></div>`
        if (orderData.hpr) {
            html += `<div class="form-control">异常挂断原因：<span style="font-weight:bold;">${orderData.hpr}</span></div>`
        } else if (orderData.hpu) {
            html += `<div class="form-control">挂断用户：<span style="font-weight:bold;">${orderData.hpu}</span></div>`
        }

        for (let key in orderData.pending) {
            html += `<hr />`
            html += `<div >用户：${key}通话过程</div>`
            for (let i = 0; i < orderData.pending[key].length; i++) {
                html += `<div class="form-control">${formatTimeMills(orderData.pending[key][i].t * 1000)} ${orderData.pending[key][i].s==0?'挂入后台':'拉起前台'}</div>`
            }
        }
        $('#LianmaiDetail').html(html)
        var index = layer.open({
            area: ['540px', '500px'],
            type: 1,
            title: '通话详情',
            content: $('#LianmaiDetail'),
            btn: ['确定'],
            yes: function (index, layero) {
                layer.close(index);
            }
        })
    }
</script>
{include file="public/footer" /}

